﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CardLogistics.Web.Components;
using System.Data;
using System.Text;

namespace CardLogistics.Web.MainPage.SystemMgr.SysLog
{
    public partial class ListInfo : BasePage
    {
        private static readonly CardLogistics.DAL.Sys.Sys_LogData DAL = new DAL.Sys.Sys_LogData ();
        protected void Page_Load(object sender, EventArgs e)
        {
            wuc_toolbar.DeleteEvent += new EventHandler(WebUserControl_ToolBar1_DeleteEvent);
            if (!IsPostBack)
            {
                BindRpt();
            }
        }

        /// <summary>
        /// 删除事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void WebUserControl_ToolBar1_DeleteEvent(object sender, EventArgs e)
        {
            string delId = this.hdf_Id.Value;
            if (!string.IsNullOrEmpty(delId))
            {
                string[] ids = delId.TrimEnd(',').Split(',');
                int resCount = 0;
                for (int i = 0; i < ids.Length; i++)
                {
                    int resStr = DAL.Delete(ids[i]);
                    if (resStr>0)
                        resCount++;
                }
                BindRpt();
            }
        }

        /// <summary>
        /// 绑定Rpt数据
        /// </summary>
        /// <param name="pageIndex"></param>
        private void BindRpt()
        {
            int recordCount = 0;
            int pageCount = 0;
            StringBuilder sbStr = new StringBuilder();
            sbStr.Append(" 1=1 ");
            if (txt_Content.Text.Trim().Length > 0)
                sbStr.Append(" and LOGCONTENT like '%" + txt_Content.Text.Trim() + "%' ");
            if (txt_Name.Text.Trim().Length > 0)
                sbStr.Append(" and (username like '%" + txt_Name.Text.Trim() + "%' or userfullname like '%" + txt_Name.Text.Trim() + "%') ");
            if (txt_StartData.Text.Trim().Length > 0)
                sbStr.Append(" and to_char(LOGDATE,'yyyy-MM-dd')>='" + txt_StartData.Text.Trim() + "'");
            if (txt_EndData.Text.Trim().Length > 0)
                sbStr.Append(" and to_char(LOGDATE,'yyyy-MM-dd')<='" + txt_EndData.Text.Trim() + "'");
            DataTable dt = CardLogistics.DAL.CommonData.QuickPage_Oracle("v_sys_log", "ID", "  LOGDATE desc ", AspNetPager1.PageSize, WebPageIndex, sbStr.ToString(), "*", out pageCount, out recordCount);
            SetNetPagerHtml(AspNetPager1, dt, rptList, recordCount);
        }


        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            WebPageIndex = AspNetPager1.CurrentPageIndex;
            BindRpt();
        }

        protected void btn_Search_Click(object sender, EventArgs e)
        {
            BindRpt();
        }
    }
}